package com.swh.utils;

import com.mysql.jdbc.StringUtils;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author: swh
 * @Description:
 * @Date: 2020/11/26 12:31
 * @Version: 1.0
 */
public class XBUtils {

    /**
     * 根据cookieName获取Request请求中的cookie数组里面的指定Cookie
     *
     * @param request
     * @param cookieName
     * @return
     */
    public static Cookie getCookie(HttpServletRequest request, String cookieName) {
        if (request.getCookies() != null && !StringUtils.isNullOrEmpty(cookieName)) {

            for (Cookie cookie : request.getCookies()) {

                if (cookie.getName().equals(cookieName)) {
                    return cookie;
                }
            }
        }
        return null;
    }
}
